package com.iuie.ns.devtools.element;

import java.util.List;

import com.iuie.ns.frame.utils.StringUtils;

public class SQLUpdateElement extends DevElement {

	private ResultMapOperationElement operationElement;
	
	public SQLUpdateElement(ResultMapOperationElement operationElement) {
		this.operationElement = operationElement;
	}
	
	@Override
	protected String getPrefix() {
		return "\t\tupdate " + this.operationElement.getHeader().getTableName() + " set \n\t\t\t";
	}

	@Override
	protected String getSuffix() {
		StringBuilder sb = new StringBuilder(12);
		sb.append("\n\t\t\t")
			.append("where ");
		DevElement element = new BaseDevElement(sb.toString(), this.operationElement.getPrimaryKeyEqualValueElements(false));
		return element.build();
	}

	@Override
	protected List<DevElement> getChildren() {
		if (StringUtils.equals(this.operationElement.getOperation(), "updateOne")) {
			return this.operationElement.getMyBatisUpdateEqualValueElements();
		}
		return null;
	}

}
